package com.di.main;

import com.di.model.User;
import com.di.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 深入浅出spring IOC中三种依赖注入方式
 *
 * https://blog.csdn.net/u011637069/article/details/51958918?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_baidulandingword-2&spm=1001.2101.3001.4242
 * 1.UserService1  是基于setter注入
 * 2.UserService  是基于构造器注入
 * 3.接口方式注入
 *
 * @author luowj12
 * @since 2021/6/16 8:48
 */
public class testMain {
    public static void main(String[] args) {
        /*//创建Spring上下文（加载bean.xml）
        ApplicationContext acx = new ClassPathXmlApplicationContext("spring-config.xml");
        //获取User实例
        User user = acx.getBean("user",User.class);
        //调用方法
        System.out.println(user.toString());*/
        ApplicationContext ac = new ClassPathXmlApplicationContext("spring-config.xml");
        // 获取bean对象
        UserService userService = ac.getBean(UserService.class, "userService1");
        // 模拟用户登录
        userService.loginUser();
    }

}
